<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link rel="icon" href="'../img/zhihu1.png'"/>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/wangEditor/10.0.13/wangEditor.min.css" >
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.10/semantic.min.css">
    <link rel="stylesheet" th:href="@{/css/global.css}" />
    <title>知识库系统-知识帖发布</title>
</head>

<body>
<div class="nk-container">
    <!-- 头部 -->
    <header class="bg-dark sticky-top" th:replace="index::header">
        <div class="container">
            <!-- 导航 -->
            <nav class="navbar navbar-expand-lg navbar-dark">
                <!-- logo -->
                <a class="navbar-brand" href="#"></a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <!-- 功能 -->
                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul class="navbar-nav mr-auto">
                        <li class="nav-item ml-3 btn-group-vertical">
                            <a class="nav-link" href="../index.html">首页</a>
                        </li>
                        <li class="nav-item ml-3 btn-group-vertical">
                            <a class="nav-link position-relative" href="letter.html">消息<span class="badge badge-danger">12</span></a>
                        </li>
                        <li class="nav-item ml-3 btn-group-vertical">
                            <a class="nav-link" href="register.html">注册</a>
                        </li>
                        <li class="nav-item ml-3 btn-group-vertical">
                            <a class="nav-link" href="login.html">登录</a>
                        </li>
                        <li class="nav-item ml-3 btn-group-vertical dropdown">
                            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                <img src="http://images.nowcoder.com/head/1t.png" class="rounded-circle" style="width:30px;"/>
                            </a>
                            <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                                <a class="dropdown-item text-center" href="profile.html">个人主页</a>
                                <a class="dropdown-item text-center" href="setting.html">账号设置</a>
                                <a class="dropdown-item text-center" href="login.html">退出登录</a>
                                <div class="dropdown-divider"></div>
                                <span class="dropdown-item text-center text-secondary">nowcoder</span>
                            </div>
                        </li>
                    </ul>
                    <!-- 搜索 -->
                    <form class="form-inline my-2 my-lg-0" action="search.html">
                        <input class="form-control mr-sm-2" type="search" aria-label="Search" />
                        <button class="btn btn-outline-light my-2 my-sm-0" type="submit">搜索</button>
                    </form>
                </div>
            </nav>
        </div>
    </header>

    <div class="main">
        <div class="container">
            <div class="editor">
                <div class="ui fluid action input">
                    <div class="ui button" style="cursor:auto">标题</div>
                    <input type="text"  id="recipient-name" required placeholder="必填">
                </div>
                <p></p>
                <div id="div1" >
                    <!--                    <p th:text="${hello}">hello</p>-->
                </div>
                <p></p>
                <div class ="publishButton">
                    <button id="publishBtn" class="btn btn-primary " type="submit">确认发布</button>
                    <button id="storageBtn" class="btn btn-primary " type="submit">保存草稿箱</button>
                </div>
            </div>
        </div>
    </div>

<!--    弹窗-->

    <div class="wrap-dialog hide">
        <div class="dialog">
            <div class="dialog-header">
                <span class="dialog-title">提示</span>
            </div>
            <div class="dialog-body">
                <span class="dialog-message">保存草稿箱？</span>
            </div>
            <div class="dialog-footer">
                <input type="button" class="btn1" id="confirm" value="确认" />
                <input type="button" class="btn1 ml50" id="cancel" value="取消" />
            </div>
        </div>
    </div>


    <footer class="bg-dark">
        <div class="container">
            <div class="row">
                <!-- 二维码 -->
                <div class="col-4 qrcode">
                    <img src="https://uploadfiles.nowcoder.com/app/app_download.png" class="img-thumbnail" style="width:136px;" />
                </div>
                <!-- 公司信息 -->
                <div class="col-8 detail-info">
                    <div class="row">
                        <div class="col">
                            <ul class="nav">
                                <li class="nav-item">
                                    <a class="nav-link text-light" href="#">关于我们</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link text-light" href="#">加入我们</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link text-light" href="#">意见反馈</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link text-light" href="#">企业服务</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link text-light" href="#">联系我们</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link text-light" href="#">免责声明</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link text-light" href="#">友情链接</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col">
                            <ul class="nav btn-group-vertical company-info">
                                <li class="nav-item text-white-50">
                                    地址：安徽省合肥市蜀山区丹霞路485号
                                </li>
                                <li class="nav-item text-white-50">
                                    <!--										联系方式：010-60728802(电话)&nbsp;&nbsp;&nbsp;&nbsp;admin@nowcoder.com-->
                                    联系方式：
                                </li>
                                <li class="nav-item text-white-50">
                                    郭襄团队©2022 All rights reserved
                                </li>
                                <li class="nav-item text-white-50">
                                    皖ICP备05018251号-4 &nbsp;&nbsp;&nbsp;&nbsp;
                                    <img src="http://static.nowcoder.com/company/images/res/ghs.png" style="width:18px;" />
                                    皖公网安备 34011102000080号
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </footer>
</div>



<script src="https://code.jquery.com/jquery-3.3.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.10/semantic.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/wangEditor/10.0.13/wangEditor.min.js"></script>
<script th:src="@{/js/global.js}"></script>
<!--<script th:src="@{js/index.js}"></script>-->
<!--     富文本编辑器配置和按钮异步请求的js处理-->
<script type="text/javascript">
    let dialog=false;
    var E = window.wangEditor
    var editor = new E('#div1')
    // 自定义菜单配置
    editor.customConfig.menus = [
        'head',
        'bold',
        'fontSize',
        'fontName',
        'italic',
        'underline',
        'strikeThrough',
        'list',
        'emoticon',
        'link',  // 插入链接
        'quote',  // 引用
        'image',  // 插入图片
        'code',  // 插入代码
        'justify',  // 对齐方式
        'undo',  // 撤销
        'redo'  // 重复
    ]
    //设置上传的参数名
    editor.customConfig.uploadFileName = 'file';
    // 上传图片到服务器
    editor.customConfig.uploadImgServer = 'http://localhost:8080/community/discuss/uploadImg'
    // 将图片大小限制为 10M
    editor.customConfig.uploadImgMaxSize = 10 * 1024 * 1024;
    editor.create();

</script>
<script>
    // 发布文章弹窗
    $(document).ready(function(){
        $('#publishBtn').click(function(){
            var message = "确认发布文章？";
            dialogBox(message,
                function () {
                    console.log("confirmed");
                    var title = $("#recipient-name").val();
                    var content = editor.txt.html()
                    console.log(content);
                    // 发送异步请求(POST)
                    $.post(
                        CONTEXT_PATH + "/discuss/uploadPost",
                        {"title":title,"content":content}
                    );
                    // 跳转回首页
                    window.location.href= CONTEXT_PATH + "/index";
                },
                function(){
                    console.log("canceled");
                    // do something
                }
            );
        });

    });

    // 草稿箱弹窗
    $(document).ready(function(){
        $('#storageBtn').click(function(){
            var message = "确认保存至草稿箱？";
            dialogBox(message,
                function () {
                    console.log("confirmed");
                    var title = $("#recipient-name").val();
                    var content = editor.txt.html()
                    console.log(content);
                    // 发送异步请求(POST)
                    $.post(
                        CONTEXT_PATH + "/discuss/uploadDraft",
                        {"title":title,"content":content},
                    );
                    // 跳转回首页
                    window.location.href= CONTEXT_PATH + "/index";
                },
                function(){
                    console.log("canceled");
                    // do something
                }
            );
        });

    });

    function dialogBox(message, yesCallback, noCallback){
        if(message){
            $('.dialog-message').html(message);
        }
        // 显示遮罩和对话框
        $('.wrap-dialog').removeClass("hide");
        // 确定按钮
        $('#confirm').click(function(){
            $('.wrap-dialog').addClass("hide");
            yesCallback();
        });
        // 取消按钮
        $('#cancel').click(function(){
            $('.wrap-dialog').addClass("hide");
            noCallback();
        });
    }
</script>


</body>
</html>
